package com.example.mountainwalker.controller;

import com.example.mountainwalker.entity.GroupTourRegistrationInfo;
import com.example.mountainwalker.entity.TravelStrategyInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/ts")

public class TravelStrategyController {

    @Autowired
    private com.example.mountainwalker.service.TravelStrategyService travelStrategyService;

    //http://localhost:8080/ts/list
    @GetMapping("/list")
    public List<TravelStrategyInfo> getTravelStrategyList() {
        List<TravelStrategyInfo> travelStrategyInfo = travelStrategyService.getTravelStrategyInfo();
        return travelStrategyInfo;
    }

    // http://localhost:8080/ts/find/1
    @GetMapping("/find/{StrategyID}")
    public TravelStrategyInfo getTravelStrategyById(@PathVariable Integer StrategyID){
        TravelStrategyInfo travelStrategyInfo = travelStrategyService.getTravelStrategyInfoById(StrategyID);
        return travelStrategyInfo;
    }

    // http://localhost:8080/ts/delete/1
    @DeleteMapping("/delete/{StrategyID}")
    public int deleteTravelStrategyById(@PathVariable("StrategyID") Integer StrategyID) {
        int result = travelStrategyService.deleteTravelStrategyInfoById(StrategyID);
        System.out.println("删除结果：" + result);  // 添加日志
        return result;
    }

    // http://localhost:8080/ts/insert
    @PostMapping("/insert")
    public int insertTravelStrategyInfo(@RequestBody TravelStrategyInfo travelStrategyInfo) {
        System.out.println("接受到的数据:"+travelStrategyInfo);
        int result = travelStrategyService.insertTravelStrategyInfo(travelStrategyInfo);
        return result;
    }

    //http://localhost:8080/ts/update
    @PutMapping("/update")
    public int updateGroupTourRegistrationInfo(@RequestBody TravelStrategyInfo travelStrategyInfo){
        int result= travelStrategyService.updateTravelStrategyInfo(travelStrategyInfo);
        return result;
    }

}
